//
//  OSCTweetDetailWithBottomBarViewController.m
//  OSChina
//
//  Created by 8b410-2 on 17/1/5.
//  Copyright © 2017年 abb. All rights reserved.
//

#import "OSCTweetDetailWithBottomBarViewController.h"
#import "OSCTweetDetailWithBottomBarViewModel.h"
#import "UITextView+OSCEmoticon.h"
@interface OSCTweetDetailWithBottomBarViewController () <OSCPopInputViewDelegate>

@property (nonatomic, strong) OSCTweetDetailWithBottomBarViewModel *viewModel;

@end

@implementation OSCTweetDetailWithBottomBarViewController

@dynamic viewModel,childVC;

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)bindViewModel {
    [super bindViewModel];
     @weakify(self);
    // 有恢复的草稿被设置 则弹出popInputview,并恢复草稿
    [[RACObserve(self.viewModel, restoreDraftAttribute) skip:1] subscribeNext:^(NSAttributedString *att) {
        @strongify(self);
        [self showEditView];
        [self.popInputView restoreDraftNoteWithAttribute:att];
    }];
    // 评论属性字符串被设置时 更改评论view里的字符串
    [[RACObserve(self.viewModel,commentViewAttribute) skip:1] subscribeNext:^(NSAttributedString *att) {
        @strongify(self);
        [self.commentView handleAttributeWithAttribute:att];
    }];
}

- (OSCPopInputView *)popInputView {
    if(!_popInputView){
        _popInputView = [OSCPopInputView popInputViewWithFrame:CGRectMake(0, kScreenSize.height - 100, kScreenSize.width, kScreenSize.height / 3) maxStringLenght:160 delegate:self autoSaveDraftNote:YES];
        _popInputView.draftKeyID = [NSString stringWithFormat:@"%ld",(long)self.viewModel.childViewModel.tweetViewModel.idField];
        _popInputView.popInputViewType = OSCPopInputViewType_At | OSCPopInputViewType_Emoji;
    }
    return _popInputView;
}

#pragma mark - OSCPopInputViewDelegate

- (void)popInputViewDidDismiss:(OSCPopInputView *)popInputView draftNoteAttribute:(NSAttributedString *)draftNoteAttribute {
    self.viewModel.commentViewAttribute = draftNoteAttribute;
}
@end
